package com.wanxi.servlet;

import com.wanxi.model.ImageShowModel;
import com.wanxi.model.NavModel;
import com.wanxi.model.TeacherModel;
import com.wanxi.service.IndexService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
//        数据给服务端处理
        IndexService indexService=new IndexService();
        List<NavModel> navModelList=new ArrayList<>();
        List<TeacherModel> teacherModelList=new ArrayList<>();
        List<ImageShowModel> imageShowModelList=new ArrayList<>();

        navModelList=indexService.getNavModelList();
        teacherModelList=indexService.getTeacherList();
        imageShowModelList=indexService.getImageShowList();

//        数据存储
        req.setAttribute("navModelList",navModelList);
        req.setAttribute("teacherModelList",teacherModelList);
        req.setAttribute("imageShowModelList",imageShowModelList);

//        页面转发
        req.getRequestDispatcher("page/index.jsp").forward(req,resp);

    }
}
